// pages/demo/demo.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
cateCode:"",
goods:[],
cateList:[],
activeIndex:0
// activeKey: 0,
  },
  onChange(event) {
    console.log('数量变化', event.detail);
  },
  stopPropagation: function(e) {
    // 阻止事件冒泡
    return false;
  },
showGoods(e){
  let that=this;
  //获取存储的code，并赋给当前页面的catecode数据
  let cateCode=e.currentTarget.dataset.code;
  let activeIndex = e.currentTarget.dataset.index;
  this.setData({ activeIndex });
  // let cateCode=wx.getStorageSync('cateCode');
  // this.setData({cateCode:cateCode})
wx.request({
  url:'http://kjxycode.zisu.edu.cn/InterfaceCommonForGoods/GetGoodsListByCate',
  data: {cateCode:cateCode,token:"kjxy_Interface_2025"},
  method: "post",
  success:function(e){
    let result=e.data.goodsList;
    // console.log(result);
    that.setData({goods:result});
  }
});
},
goToDetail(e) {
  const goods = e.currentTarget.dataset.goods;
  wx.navigateTo({
    url: `/pages/detail/detail?goodsDetail=${JSON.stringify(goods)}`
  });
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let currentCateList=wx.getStorageSync('cateList');
    // console.log("目前的商品类别",currentCateList);
    this.setData({cateList:currentCateList})
    // console.log(options)
    // let cateCode=wx.getStorageSync('coteCode');
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  // onReady() {
  // },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that=this;
    //获取存储的code，并赋给当前页面的catecode数据
    let cateCode=wx.getStorageSync('cateCode');
    let currentCateList=wx.getStorageSync('cateList');
for(let i=0;i<currentCateList.length;i++){
  if(cateCode==currentCateList[i].cateCode){
    this.setData({activeIndex:i});
    break;
  }
}
    // console.log("当前类别编号：cateCode"=+cateCode,Number(cateCode));
    // this.setData({activeIndex:Number(cateCode)-1})
    // this.setData({cateCode:cateCode})
  wx.request({
    url:'http://kjxycode.zisu.edu.cn/InterfaceCommonForGoods/GetGoodsListByCate',
    data: {cateCode:cateCode,token:"kjxy_Interface_2025"},
    method: "post",
    success:function(e){
      let result=e.data.goodsList;
      // console.log(result);
      that.setData({goods:result});
    }
  });
  }
});
  /**
   * 生命周期函数--监听页面隐藏
   */
  // onHide() {

  // },

  /**
   * 生命周期函数--监听页面卸载
   */
  // onUnload() {

  // },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  // onPullDownRefresh() {

  // },

  /**
   * 页面上拉触底事件的处理函数
   */
  // onReachBottom() {

  // },

  /**
   * 用户点击右上角分享
   */
//   onShareAppMessage() {

//   }
// });
